/*global jQuery: false, document: false */

/*members article_name, attr, cancel, company_id, company_name, editable, 
 indicator, method, ready, style, submit, submitdata, text, tooltip, 
 type
 */

var commaSeparator = $("<span>, </span>")

jQuery(document).ready(function () {

    var submit_data = {
        company_id: jQuery("h1.title").attr("id"),
        article_name: jQuery("h1.title").text() + " overview",
        company_name: jQuery("h1.title").text()
    };


    function makeTickerSymbolEditable(el) {
        el.editable("/company_write/ticker_symbol/", {
            type: "ticker_symbol",
            submit: "OK",
            cancel: "Cancel",
            indicator: "Saving...",
            tooltip: '',
            submitdata: submit_data
        });
    }

    makeTickerSymbolEditable($("p.ticker_symbol span.editable"));

    jQuery($("div.ticker_symbol input.add").click(function() {
        $("p.ticker_symbol").append(commaSeparator).append($('<span class="editable"></span>'));
        var lastEditableDiv = $("p.ticker_symbol span.editable:last");
        makeTickerSymbolEditable(lastEditableDiv);
        lastEditableDiv.click();
    }));

    jQuery("#overview").editable("/company_write/overview/", {
        type: "textarea",
        submit: "OK",
        method: "POST",
        submitdata: submit_data,
        indicator: "Saving...",
        tooltip: "Click to edit..."
    });

    jQuery("p.technologies_involved span.editable").editable("/echo/", {
        indicator: "Saving...",
        submitdata: submit_data,
        style: "inherit"
    });

    jQuery("p span.area_of_expertise").editable("/company_write/area_of_expertise/", {
        type: "area_of_expertise",
        submit: "OK",
        cancel: "Cancel",
        indicator: "Saving...",
        submitdata: submit_data
    });

});
